<{include file="Public/top.html" }>
</head>
<body>
<div id="warpper">
    <div class="content">
        <div class="location">抽奖记录</div>
        <{include file="./nav.html" }>
        <div class="filedSet" style="padding-bottom: 0;">
            <div class="search">
                <form action="" id="searchForm" method="get" class="ui-form reportForm">
                    <input name="m" type="hidden" value="<{$module}>">
                    <input name="c" type="hidden" value="<{$controller}>">
                    <input name="a" type="hidden" value="<{$action}>">

                    <input name="p" id="page" type="hidden" value="<{$page|default:1}>">
                    <input name="type" type="hidden" value="3">
                    <input name="limit" id="limit" type="hidden" value="<{$limit|default:10}>">
                    <!--<input name="ofield" id="ofield" type="hidden" value="<{$ofield}>">-->
                    <!--<input name="otype"  id="otype"  type="hidden" value="<{$otype}>">-->

                    <div class="ui-form-item inline-block">
                        <label class="ui-label">开始时间</label>
                        <input  id="startDate2" name="beginDate" class="date ui-text" type="text" value="<{$beginDate}>"  readonly style="width: 80px">
                    </div>
                    <div class="ui-form-item inline-block">
                        <label class="ui-label">结束时间</label>
                        <input  id="endDate2" name="endDate" class="date ui-text" type="text" value="<{$endDate}>"  readonly/>
                    </div>

                    <div class="ui-form-item inline-block">
                        <input type="text" value="<{$keyword}>" class="ui-text bg-text keyword" name="keyword" placeholder="姓名" style="width: 80px;" />
                    </div>

                    <div class="ui-form-item inline-block">
                        <input type="text" value="<{$phone}>" class="ui-text bg-text " name="phone" placeholder="手机号" style="width: 80px;" />
                    </div>
                    <div class="ui-form-item inline-block">
                        <input type="text" value="<{$prize}>" class="ui-text bg-text " name="prize" placeholder="奖品" style="width: 80px;" />
                    </div>
                    <div class="ui-form-item inline-block">
                        <label class="ui-label">关联</label>
                        <select name="mapping"  class="ui-select" >
                            <option value="0">全部</option>
                            <{html_options options=$mappingKv selected=$mapping}>
                        </select>
                    </div>

                    <div class="ui-form-item inline-block">
                        <button type="submit" class="ui-button" onclick="LayerShow();">搜索</button>
                    </div>

                    <div class="ui-form-item inline-block">
                        <button type="button" class="ui-button" onclick="exportData()">导出</button>
                    </div>
                </form>
            </div>
        </div>


        <!--表格内容-->
        <div class="mainGrid">
            <table class="ui-table ui-body">
                <thead>
                <tr>
                    <th class="pct10">中奖时间</th>
                    <th class="pct10">用户昵称</th>
                    <th class="pct10">用户姓名</th>
                    <th class="pct10">用户手机</th>
                    <th class="pct10">活动关联</th>
                    <th class="pct15">奖品说明</th>
                    <th class="pct25">收货地址</th>
                    <th class="pct12 last-col">发货状态</th>
                </tr>
                </thead>
                <tbody>
                <{if $data}>
                    <{foreach from=$data item=item}>
                    <tr>
                        <td><{$item.addTime|date_format:'%Y-%m-%d <br/> %H:%M:%S'}></td>
                        <td><{$item.nickname}></td>
                        <td><{$item.realName}></td>
                        <td><{$item.bindPhone}></td>
                        <td><{$mappingKv[$item.mid]}></td>
                        <td title="<{$item.prizeName}>"><{$item.prizeName}></td>
                        <td title="<{$item.address}>"><{$item.address}></td>
                        <td id="status<{$item.id}>">
                            <{if $item.status > 1}>
                                <a style="color:#2077d1;" href="javascript:toggle(<{$item.id}>,<{$item.status}>);"><{$item.statusText}></a>
                            <{else}>
                                <{$item.statusText}>
                            <{/if}>
                        </td>
                    </tr>
                    <{/foreach}>
                <{else}>
                    <tr><td colspan="7">无中奖记录</td></tr>
                <{/if}>
                </tbody>
            </table>
        </div>
        <div class="pagination">
            <!--描述：分页-->
            <{include file="Public/page.html" }>
        </div>
    </div>
</div>
<{include file="Public/foot.html" }>
</body>
</html>
<script>
    datePickter('startDate2','endDate2',true);

    function toggle(i,status) {
        var confirm = '';
        if(status == 2){
            confirm = '改回未发';
        } else if(status == 3){
            confirm = '确认发货';
        }
        $("#status"+i).empty().append('<a style="color:#2077d1;" href="javascript:commit(\''+i+'\',\''+status+'\');">'+confirm+'</a>  <a style="color:#2077d1;" href="javascript:cancel(\''+i+'\',\''+status+'\');">取消</a>')
    }
    function cancel(i,status) {
        var text = "";
        if(status == 2){
            text = "已发货";
        }else if(status == 3){
            text = "未发货";
        }
        $("#status"+i).empty().append('<a style="color:#2077d1;" href="javascript:toggle(\''+i+'\',\''+status+'\');">'+text+'</a>');
    }
    function commit(i,status) {
        $.get("<{U('updatePrizeStatus')}>",{'id':i,'status':status},function (res) {
            layer.msg(res.msg);
            if(res.status > 0){
                $("#status"+i).empty().append('<a href="javascript:toggle(\''+i+'\',\''+res.status+'\');">'+res.note+'</a>');
            }
        });
    }
    function exportData(){
        var exportUrl = "<{U('prizeLog')}>";
        window.location.href = exportUrl+'&export=1&'+$("#searchForm").serialize()
    }
</script>
